package com.uzai.console.service.zombiefan.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import com.uzai.common.entity.User;
import com.uzai.common.enums.*;
import com.uzai.common.exception.BusinessException;
import com.uzai.common.msg.MsgDto;
import com.uzai.common.msg.NoticeMsgDto;
import com.uzai.common.result.ResponseCode;
import com.uzai.common.utils.EsIndexName;
import com.uzai.console.common.utils.DateUtil;
import com.uzai.console.common.utils.Tools;
import com.uzai.console.constant.Const;
import com.uzai.console.constant.ES.ElasticsearchUtilGroupMsg;
import com.uzai.console.dto.order.OrderQuery;
import com.uzai.console.dto.rocketmq.friendrequest.DeleteUserDto;
import com.uzai.console.dto.rocketmq.wechatuser.SetUserRemarkDto;
import com.uzai.console.dto.takebal.usertakebal.UserTakeBalQuery;
import com.uzai.console.dto.tb.tborder.TbOrderQuery;
import com.uzai.console.dto.zombiefan.zombiefan.ZombieFanQuery;
import com.uzai.console.dto.zombiefan.zombiefantask.ZombieFanTaskQuery;
import com.uzai.console.entity.*;
import com.uzai.console.enums.ZombieFanTaskStatusEnum;
import com.uzai.console.mapper.*;
import com.uzai.console.service.device.DeviceService;
import com.uzai.console.service.merchant.MerchantService;
import com.uzai.console.service.order.OrderOptService;
import com.uzai.console.service.rocketmq.NoticeMsgPushProducerService;
import com.uzai.console.service.user.UserService;
import com.uzai.console.service.wechatprivate.WxContactsService;
import com.uzai.console.service.wechatwork.WxworkContactsService;
import com.uzai.console.service.zombiefan.ZombieFanTaskSendInfoService;
import com.uzai.console.vo.order.BaseOrderVo;
import com.uzai.console.vo.takebal.usertakebal.UserTakeBalReportVo;
import org.apache.logging.log4j.util.Strings;
import org.checkerframework.checker.units.qual.A;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * 自动清理僵尸粉任务发送明细
 * @author liuqi
 * @date 2021年08月13日 11:34
 */
@Service
public class ZombieFanTaskSendInfoServiceImpl implements ZombieFanTaskSendInfoService {

    Logger logger = LoggerFactory.getLogger(ZombieFanTaskSendInfoServiceImpl.class);

    @Autowired
    private ZombieFanTaskMapper zombieFanTaskMapper;
    @Autowired
    private ZombieFanTaskSendInfoMapper zombieFanTaskSendInfoMapper;
    @Autowired
    private ZombieFanMapper zombieFanMapper;
    @Autowired
    private DeviceService deviceService;
    @Autowired
    private DeviceWechatInfoMapper deviceWechatInfoMapper;
    @Autowired
    private DeviceWxworkInfoMapper deviceWxworkInfoMapper;
    @Autowired
    private WxContactsService wxContactsService;
    @Autowired
    private WxworkContactsService wxworkContactsService;
    @Autowired
    private NoticeMsgPushProducerService noticeMsgPushProducerService;
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private MerchantService merchantService;
    @Autowired
    private ElasticsearchUtilGroupMsg elasticsearchUtilGroupMsg;
    @Autowired
    private UserService userService;
    @Autowired
    private UserTakeBalMapper userTakeBalMapper;
    @Autowired
    private OrderOptService orderOptService;

    /**
     * 自动检查个人微信清理僵尸粉任务发送明细
     * @author liuqi
     * @date 2021/8/13 11:38
     * @param zombieFanTask
     * @return null
     */
    public void autoCheckZomBieFanTaskSendInfo(ZombieFanTask zombieFanTask){
        if(zombieFanTask == null){
            throw  new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "自动清理僵尸粉任务不存在");
        }

        Long deviceUniqueId = zombieFanTask.getDeviceUniqueId();
        if(deviceUniqueId == null){
            throw  new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "该任务未关联机器人");
        }

        Device device = deviceService.findDeviceInfoByDeviceUniqueId(deviceUniqueId, zombieFanTask.getDeviceType(), zombieFanTask.getMerId());
        if(device == null){
            throw  new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "该机器人为空");
        }

        //查询该机器人关联的最小id的发送明细
        ZombieFanTaskSendInfo zombieFanTaskSendInfo = zombieFanTaskSendInfoMapper.selectMinIdByDeviceUniqueId(deviceUniqueId, zombieFanTask.getMerId());
        if(zombieFanTaskSendInfo != null){ //检查中,发送普通消息
            //删除数据库该记录
            zombieFanTaskSendInfoMapper.deleteById(zombieFanTaskSendInfo.getId(), zombieFanTaskSendInfo.getMerId());

            //保存到redis当中，用于手机端区分是否主动僵尸粉还是被动僵尸粉
            String redis_key = String.format(RedisCacheKeyEnum.ZOMBIE_FAN_CHECK.getKey(), zombieFanTask.getMerId(), device.getDeviceId(), zombieFanTaskSendInfo.getWxid());
            String remark = Tools.getStr(zombieFanTask.getZombieRemark()).replace("[昵称]", Tools.getStr(zombieFanTaskSendInfo.getNick()))
                    .replace("[时间]", Tools.getCurrentTimeByFormat("yyyy-MM-dd"));
            if(StringUtils.isBlank(remark)){
                remark = Const.ZonbieFan.notUpdateRemark;
            }
            redisTemplate.opsForValue().set(redis_key, remark, 1, TimeUnit.MINUTES);

            //发送检查是否僵尸粉MQ消息
            if(Tools.getInteger(zombieFanTask.getCheckType()).intValue() == 1){ //群发文本消息检测
                //发送MQ消息
                MsgDto<NoticeMsgDto>  msgDto = new MsgDto<>();
                NoticeMsgDto  noticeMsgDto = new NoticeMsgDto();
                msgDto.setContent(noticeMsgDto);
                msgDto.setId(IdWorker.getId());
                msgDto.setDeviceType(device.getRecvmsgType());
                msgDto.setDeviceUniqueId(deviceUniqueId);
                msgDto.setMerId(zombieFanTask.getMerId());
                msgDto.setMsgType(MessageFuncEnum.SEND_CHAT_MESSAGE.getValue());
                msgDto.setCsMsg(true); //客服消息不走悠聊系统
                String msg = Tools.getStr(zombieFanTask.getCheckMsg());
                noticeMsgDto.setContent(msg.replace("[昵称]", zombieFanTaskSendInfo.getNick()));
                noticeMsgDto.setBizUserId(zombieFanTaskSendInfo.getWxid());
                noticeMsgDto.setContentType(MessageTypeEnum.MT_TEXT.getValue());
                noticeMsgDto.setGroupId(null);
                noticeMsgDto.setNickName(zombieFanTaskSendInfo.getNick());
                noticeMsgDto.setMsgSource(1);
                noticeMsgDto.setMsgBizType(KefuSendMsgEnum.UNSOLICITEDMSG.getKey());
                noticeMsgPushProducerService.sendMessage(msgDto);
            }else{//无痕检测
                MsgDto<NoticeMsgDto> msgDto = new MsgDto<>();
                NoticeMsgDto  noticeMsgDto = new NoticeMsgDto();
                msgDto.setContent(noticeMsgDto);
                msgDto.setId(IdWorker.getId());
                msgDto.setDeviceType(device.getRecvmsgType());
                msgDto.setDeviceUniqueId(deviceUniqueId);
                msgDto.setMerId(zombieFanTask.getMerId());
                msgDto.setMsgType(MessageFuncEnum.SEND_CHAT_MESSAGE.getValue());
                msgDto.setCsMsg(true); //客服消息不走悠聊系统
                noticeMsgDto.setContent(Const.ZonbieFan.content); //指定的清理僵尸粉内容
                noticeMsgDto.setBizUserId(zombieFanTaskSendInfo.getWxid());
                noticeMsgDto.setContentType(MessageTypeEnum.MT_NAME_CARD.getValue());
                noticeMsgDto.setGroupId(null);
                noticeMsgDto.setNickName(null);
                noticeMsgDto.setMsgSource(1);
                noticeMsgDto.setDelay(0);
                noticeMsgDto.setMsgBizType(KefuSendMsgEnum.UNSOLICITEDMSG.getKey());
                noticeMsgPushProducerService.sendMessage(msgDto);
            }

            //修改清理僵尸粉任务，检查数+1
            zombieFanTask.setCheckNum(zombieFanTask.getCheckNum() + 1);
            zombieFanTaskMapper.updateById(zombieFanTask);
        }else{ //检查完成，则需要修改检查任务为清粉中
            zombieFanTask.setStatus(ZombieFanTaskStatusEnum.DELETING.getId());
            zombieFanTaskMapper.updateById(zombieFanTask);
        }
    }

    /**
     * 自动清理个人微信清理僵尸粉任务发送明细
     * @author liuqi
     * @date 2021/8/13 11:38
     * @param zombieFanTask
     * @return null
     */
    public void autoDeleteZomBieFanTaskSendInfo(ZombieFanTask zombieFanTask){
        if(zombieFanTask == null){
            throw  new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "自动清理僵尸粉任务不存在");
        }

        Long deviceUniqueId = zombieFanTask.getDeviceUniqueId();
        if(deviceUniqueId == null){
            throw  new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "该任务未关联机器人");
        }

        Device device = deviceService.findDeviceInfoByDeviceUniqueId(deviceUniqueId, zombieFanTask.getDeviceType(), zombieFanTask.getMerId());
        if(device == null){
            throw  new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "该机器人为空");
        }

        //查询该机器人关联的最小id的发送明细
        ZombieFan zombieFan = zombieFanMapper.selectMinIdByDeviceUniqueId(deviceUniqueId, zombieFanTask.getMerId());
        if(zombieFan != null){ //清除中
            //删除ES记录
            //通过查询运营商其他索引分片获取分片索引
            String esName = EsIndexName.UZAI_WX_CONTACTS; //默认个人微信
            //企业微信
            if(DeviceTypeEnum.DT_WORK_WECHAT.getKey().equals(zombieFanTask.getDeviceType())){
                esName = EsIndexName.UZAI_WORKWX_CONTACTS;
            }
            String mechantOtherEsIndexName = merchantService.getMechantOtherEsIndexName(esName, zombieFanTask.getMerId());
            //删除通讯录
            String id = zombieFanTask.getMerId() + "_" + device.getDeviceId() + "_" + zombieFan.getWxid();
            elasticsearchUtilGroupMsg.deleteDataById(mechantOtherEsIndexName, id);
            //删除会员
            if(Tools.getInteger(zombieFanTask.getDelUser()).intValue() == 1){ //开启清除0积分0余额的会员
                User userInfoByWxid = userService.findUserInfoByWxid(zombieFan.getMerId(), zombieFan.getWxid(), zombieFan.getDeviceType());
                if(userInfoByWxid != null){
                    //是否能删除会员判断
                    boolean deleteUserFlag = deleteUserFlag(userInfoByWxid);
                    if(deleteUserFlag){//能删除
                        userService.deleteUserInfoByWxid(zombieFan.getMerId(), zombieFan.getWxid(), zombieFan.getDeviceType());
                    }
                }
            }

            //发送MQ消息
            MsgDto<DeleteUserDto> msgDto = new MsgDto<>();
            DeleteUserDto deleteUserDto = new DeleteUserDto();
            deleteUserDto.setWxid(zombieFan.getWxid());
            msgDto.setContent(deleteUserDto);
            msgDto.setId(IdWorker.getId());
            msgDto.setDeviceType(device.getRecvmsgType());
            msgDto.setDeviceUniqueId(deviceUniqueId);
            msgDto.setMerId(zombieFanTask.getMerId());
            msgDto.setMsgType(MessageFuncEnum.DELETE_USER.getValue());
            noticeMsgPushProducerService.deleteUser(msgDto);

            //修改僵尸粉记录
            zombieFan.setStatus(1); //已处理
            zombieFanMapper.updateById(zombieFan);

            //修改清理僵尸粉，当日清理数+1
            zombieFanTask.setDelDayNum(zombieFanTask.getDelDayNum() + 1);
            zombieFanTaskMapper.updateById(zombieFanTask);

        }else{//清除完成，则需要修改检查任务为已完成
            zombieFanTask.setStatus(ZombieFanTaskStatusEnum.COMPLETED.getId());
            zombieFanTaskMapper.updateById(zombieFanTask);
        }
    }

    /**
     * 清除所有僵尸粉中余额和积分都为0的会员数据
     * @author liuqi
     * @date 2021/8/13 11:38
     * @param zombieFanTask
     * @return null
     */
    public void autoDeleteUser(ZombieFanTask zombieFanTask){
        ZombieFanQuery zombieFanQuery = new ZombieFanQuery();
        zombieFanQuery.setDeviceUniqueId(zombieFanTask.getDeviceUniqueId());
        //查询所有的自动发圈配置记录
        Page<ZombieFan> page = new Page<>();
        page.setCurrent(1);//只查第一页
        page.setSize(10); //每页查询10个
        page.addOrder(OrderItem.asc("id"));//默认id升序
        Long idStart = 0L;
        List<ZombieFan> zombieFanList = zombieFanMapper.findByList(page, zombieFanQuery);
        while (zombieFanList != null && zombieFanList.size() > 0){
            for (ZombieFan zombieFan : zombieFanList){
                try{

                    if(zombieFan.getId().longValue() > idStart.longValue()){
                        idStart = zombieFan.getId();
                    }

                    User userInfoByWxid = userService.findUserInfoByWxid(zombieFan.getMerId(), zombieFan.getWxid(), zombieFan.getDeviceType());
                    if(userInfoByWxid != null){
                        //判断是否能删除会员
                        boolean deleteUserFlag = deleteUserFlag(userInfoByWxid);
                        if(!deleteUserFlag){
                            continue;
                        }

                        //删除会员数据
                        userService.deleteUserInfoByWxid(zombieFan.getMerId(), zombieFan.getWxid(), zombieFan.getDeviceType());
                        //修改ES备注和手机通讯录备注
                        String deUserRemark = Tools.getStr(zombieFanTask.getDelUserRemark()).replace("[昵称]", Tools.getStr(zombieFan.getNickName()))
                                .replace("[时间]", Tools.getCurrentTimeByFormat("yyyy-MM-dd"));
                        //不等于空，表示需要修改通讯录备注
                        if(StringUtils.isNotBlank(deUserRemark)){

                            //修改僵尸粉表里的备注
                            zombieFan.setRemark(deUserRemark);
                            zombieFanMapper.updateById(zombieFan);

                            //查询该机器人是否存在
                            Device device = deviceService.findDeviceInfoByDeviceUniqueId(zombieFan.getDeviceUniqueId(), zombieFanTask.getDeviceType(), zombieFanTask.getMerId());
                            if(device != null){
                                //发送MQ消息
                                MsgDto<SetUserRemarkDto> msgDto = new MsgDto<>();
                                SetUserRemarkDto setUserRemarkDto = new SetUserRemarkDto();
                                msgDto.setContent(setUserRemarkDto);
                                msgDto.setId(IdWorker.getId());
                                msgDto.setDeviceUniqueId(device.getId());
                                msgDto.setDeviceType(device.getRecvmsgType());
                                msgDto.setMerId(device.getMerId());
                                msgDto.setMsgType(MessageFuncEnum.SET_USER_REMARK.getValue());
                                setUserRemarkDto.setWxid(userInfoByWxid.getBizUserId());
                                setUserRemarkDto.setRemark(Tools.getStr(deUserRemark));
                                noticeMsgPushProducerService.setUserRemark(msgDto);

                                //修改通讯录中的备注信息
                                //通过查询运营商其他索引分片获取分片索引
                                String esName = EsIndexName.UZAI_WX_CONTACTS; //默认个人微信
                                //企业微信
                                if(DeviceTypeEnum.DT_WORK_WECHAT.getKey().equals(zombieFanTask.getDeviceType())){
                                    esName = EsIndexName.UZAI_WORKWX_CONTACTS;
                                }
                                String mechantOtherEsIndexName = merchantService.getMechantOtherEsIndexName(esName, zombieFanTask.getMerId());
                                //修改通讯录备注
                                String id = zombieFanTask.getMerId() + "_" + device.getDeviceId() + "_" + zombieFan.getWxid();
                                JSONObject jsonObject = new JSONObject();
                                jsonObject.put("remark", deUserRemark);
                                elasticsearchUtilGroupMsg.updateDataById(jsonObject, mechantOtherEsIndexName, id);
                            }
                        }
                    }
                }catch (Exception e){
                    logger.error("--自动删除僵尸粉所有的会员数据失败--error={}",e.getMessage());
                }
            }

            zombieFanQuery.setIdStart(idStart);
            zombieFanList = zombieFanMapper.findByList(page, zombieFanQuery);
        }
    }

    /**
     * 验证是否能删除此会员
     * @author jitwxs
     * @date 2023/12/11 10:21
     * @param userInfoByWxid
     * @return boolean
     */
    public boolean deleteUserFlag(User userInfoByWxid){
        //判断删除会员条件，满足是否有积分、有余额，是否有提现记录，是否有未结算订单，是否有多个机器人会员
        boolean deleteUserFlag = true; //默认可以可以删除
        //是否有多个客户端
        if(Strings.isNotBlank(userInfoByWxid.getDeviceInfos())){
            List<String> deviceInfoList = JSONObject.parseArray(userInfoByWxid.getDeviceInfos(), String.class);
            if(deviceInfoList != null && deviceInfoList.size() >= 2){
                deleteUserFlag = false;
                return deleteUserFlag; //不能删除
            }
        }

        //是否积分和余额为0
        int integral = Tools.getInteger(userInfoByWxid.getIntegral()).intValue();
        double balance = Tools.getDouble(userInfoByWxid.getBalance()).doubleValue();
        if(integral != 0 || balance != 0.00){
            deleteUserFlag = false;
            return deleteUserFlag; //不能删除
        }

        //判断此会员是否有未提现的记录，如果有，则不删除
        UserTakeBalQuery userTakeBalQuery = new UserTakeBalQuery();
        userTakeBalQuery.setMerId(userInfoByWxid.getMerId());
        userTakeBalQuery.setUserId(userInfoByWxid.getId());
        //待处理和待处理(自动提现失败)
        userTakeBalQuery.setStatusList(Lists.newArrayList(TakeBalStatusEnum.TBS_PENDING.getValue(), TakeBalStatusEnum.TBS_AUTO_TAKEBAL_FAIL.getValue())); //待处理和自动处理失败
        UserTakeBalReportVo userTakeBalReportVo = userTakeBalMapper.selectUserTakeBalReport(userTakeBalQuery);
        //如果有未提现记录，且未提现记录数量大于0
        if(userTakeBalReportVo != null && userTakeBalReportVo.getTakeBalCount().intValue() > 0){
            deleteUserFlag = false;
            return deleteUserFlag; //不能删除
        }

        //淘宝是否有付款和维权中的订单
        OrderQuery orderQuery_status = new OrderQuery();
        orderQuery_status.setMerId(userInfoByWxid.getMerId());
        orderQuery_status.setUserId(userInfoByWxid.getId());
        orderQuery_status.setStatusList(Lists.newArrayList(OrderStatusEnum.STATUS_PAID.getValue(), OrderStatusEnum.STATUS_REFUNDING.getValue()));
        //是否有淘宝订单
        Page<BaseOrderVo> baseOrderList_tb_status = orderOptService.findBaseOrderList(orderQuery_status, PlatformTypeEnum.PT_TAOBAO_VALUE);
        if(baseOrderList_tb_status != null && baseOrderList_tb_status.getTotal() > 0){
            deleteUserFlag = false;
            return deleteUserFlag; //不能删除
        }
        //是否有京东订单
        Page<BaseOrderVo> baseOrderList_jd_status = orderOptService.findBaseOrderList(orderQuery_status, PlatformTypeEnum.PT_JD_VALUE);
        if(baseOrderList_jd_status != null && baseOrderList_jd_status.getTotal() > 0){
            deleteUserFlag = false;
            return deleteUserFlag; //不能删除
        }
        //是否有拼多多订单
        Page<BaseOrderVo> baseOrderList_pdd_status = orderOptService.findBaseOrderList(orderQuery_status, PlatformTypeEnum.PT_PDD_VALUE);
        if(baseOrderList_pdd_status != null && baseOrderList_pdd_status.getTotal() > 0){
            deleteUserFlag = false;
            return deleteUserFlag; //不能删除
        }
        //是否有唯品会订单
        Page<BaseOrderVo> baseOrderList_vph_status = orderOptService.findBaseOrderList(orderQuery_status, PlatformTypeEnum.PT_VPH_VALUE);
        if(baseOrderList_vph_status != null && baseOrderList_vph_status.getTotal() > 0){
            deleteUserFlag = false;
            return deleteUserFlag; //不能删除
        }
        //是否有美团订单
        Page<BaseOrderVo> baseOrderList_mt_status = orderOptService.findBaseOrderList(orderQuery_status, PlatformTypeEnum.PT_MT_LM_VALUE);
        if(baseOrderList_mt_status != null && baseOrderList_mt_status.getTotal() > 0){
            deleteUserFlag = false;
            return deleteUserFlag; //不能删除
        }
        //是否有饿了么订单
        Page<BaseOrderVo> baseOrderList_elm_status = orderOptService.findBaseOrderList(orderQuery_status, PlatformTypeEnum.PT_ELM_VALUE);
        if(baseOrderList_elm_status != null && baseOrderList_elm_status.getTotal() > 0){
            deleteUserFlag = false;
            return deleteUserFlag; //不能删除
        }
        //是否有抖音订单
        Page<BaseOrderVo> baseOrderList_dy_status = orderOptService.findBaseOrderList(orderQuery_status, PlatformTypeEnum.PT_DY_VALUE);
        if(baseOrderList_dy_status != null && baseOrderList_dy_status.getTotal() > 0){
            deleteUserFlag = false;
            return deleteUserFlag; //不能删除
        }
        //是否有快手订单
        Page<BaseOrderVo> baseOrderList_ks_status = orderOptService.findBaseOrderList(orderQuery_status, PlatformTypeEnum.PT_KS_VALUE);
        if(baseOrderList_ks_status != null && baseOrderList_ks_status.getTotal() > 0){
            deleteUserFlag = false;
            return deleteUserFlag; //不能删除
        }


        //淘宝是否有未返利和返利冻结中的订单
        OrderQuery orderQuery_reStatus = new OrderQuery();
        orderQuery_reStatus.setMerId(userInfoByWxid.getMerId());
        orderQuery_reStatus.setUserId(userInfoByWxid.getId());
        orderQuery_reStatus.setReStatusList(Lists.newArrayList(OrderReStatusEnum.RE_STATUS_FROZEN.getValue()));
        //是否有淘宝订单
        Page<BaseOrderVo> baseOrderList_tb_restatus = orderOptService.findBaseOrderList(orderQuery_reStatus, PlatformTypeEnum.PT_TAOBAO_VALUE);
        if(baseOrderList_tb_restatus != null && baseOrderList_tb_restatus.getTotal() > 0){
            deleteUserFlag = false;
            return deleteUserFlag; //不能删除
        }
        //是否有京东订单
        Page<BaseOrderVo> baseOrderList_jd_restatus = orderOptService.findBaseOrderList(orderQuery_reStatus, PlatformTypeEnum.PT_JD_VALUE);
        if(baseOrderList_jd_restatus != null && baseOrderList_jd_restatus.getTotal() > 0){
            deleteUserFlag = false;
            return deleteUserFlag; //不能删除
        }
        //是否有拼多多订单
        Page<BaseOrderVo> baseOrderList_pdd_restatus = orderOptService.findBaseOrderList(orderQuery_reStatus, PlatformTypeEnum.PT_PDD_VALUE);
        if(baseOrderList_pdd_restatus != null && baseOrderList_pdd_restatus.getTotal() > 0){
            deleteUserFlag = false;
            return deleteUserFlag; //不能删除
        }
        //是否有唯品会订单
        Page<BaseOrderVo> baseOrderList_vph_restatus = orderOptService.findBaseOrderList(orderQuery_reStatus, PlatformTypeEnum.PT_VPH_VALUE);
        if(baseOrderList_vph_restatus != null && baseOrderList_vph_restatus.getTotal() > 0){
            deleteUserFlag = false;
            return deleteUserFlag; //不能删除
        }
        //是否有美团订单
        Page<BaseOrderVo> baseOrderList_mt_restatus = orderOptService.findBaseOrderList(orderQuery_reStatus, PlatformTypeEnum.PT_MT_LM_VALUE);
        if(baseOrderList_mt_restatus != null && baseOrderList_mt_restatus.getTotal() > 0){
            deleteUserFlag = false;
            return deleteUserFlag; //不能删除
        }
        //是否有饿了么订单
        Page<BaseOrderVo> baseOrderList_elm_restatus = orderOptService.findBaseOrderList(orderQuery_reStatus, PlatformTypeEnum.PT_ELM_VALUE);
        if(baseOrderList_elm_restatus != null && baseOrderList_elm_restatus.getTotal() > 0){
            deleteUserFlag = false;
            return deleteUserFlag; //不能删除
        }
        //是否有抖音订单
        Page<BaseOrderVo> baseOrderList_dy_restatus = orderOptService.findBaseOrderList(orderQuery_reStatus, PlatformTypeEnum.PT_DY_VALUE);
        if(baseOrderList_dy_restatus != null && baseOrderList_dy_restatus.getTotal() > 0){
            deleteUserFlag = false;
            return deleteUserFlag; //不能删除
        }
        //是否有快手订单
        Page<BaseOrderVo> baseOrderList_ks_restatus = orderOptService.findBaseOrderList(orderQuery_reStatus, PlatformTypeEnum.PT_KS_VALUE);
        if(baseOrderList_ks_restatus != null && baseOrderList_ks_restatus.getTotal() > 0){
            deleteUserFlag = false;
            return deleteUserFlag; //不能删除
        }

        return deleteUserFlag;
    }
}
